import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
// @ts-ignore
import path from 'path';
// @ts-ignore 引入插件处理gzip;
import viteCompression from 'vite-plugin-compression';
// @ts-ignore;
import Components from 'unplugin-vue-components/vite';
// @ts-ignore;
import {VantResolver, ElementPlusResolver} from 'unplugin-vue-components/resolvers';

export default defineConfig(({command, mode}) => {
    let config = {
        base: "./",
        plugins: [
            viteCompression(),
            Components({
                resolvers: [VantResolver(), ElementPlusResolver()],
            }),
            vue(),
        ],
        server: {
            port: 9999,
            fs: {
                strict: false
            },
        },
        resolve: {
            alias: {
                // @ts-ignore
                "src": path.join(__dirname, "src"),
                // @ts-ignore
                "api": path.join(__dirname, "src/assets/api/rearEnd/api.ts"),
                // @ts-ignore
                "ue4Api": path.join(__dirname, "src/assets/api/UE4/index.ts"),
                // @ts-ignore
                "tool": path.join(__dirname, "src/assets/js/tool.ts"),
            }
        },
        build: {
            outDir: "./server_init/dist",
            chunkSizeWarningLimit: 1500,
            minify: "terser",
            terserOptions: {
                compress: {
                    drop_console: false,
                    drop_debugger: false,
                }
            }
        }
    };
    // 如果现在是打包的命令并且是预发版状态需要清除日志和debugger;
    if (command == "build" && (mode == "pre-release1" || mode == "release")) {
        config.build.terserOptions.compress.drop_console = true;
        config.build.terserOptions.compress.drop_debugger = true;
    }
    return config;
})
